home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / vlclass.exe / CHGVOL.CPP < prev    next >
C/C++ Source or Header  |  1991-11-20  |  2KB  |  72 lines

  1. // CHGVOL - Change Volume Label program
  2. // Copyright 1991 - By Tom Astin - 73407,3427
  3. // Use as is. Not responisble for performance
  4. // Demonstrates use of VOLLAB.CPP (class VolLabel)
  5. // See VOLLAB.H for brief documentation
  6. // Minimal testing done.
  7.  
  8. #include <iostream.h>
  9. #include <stdlib.h>
  10. #include <ctype.h>
  11. #include "vollab.h"
  12.  
  13. void ErrorMsg(char *msg)
  14. {
  15.     cout << msg << endl << endl;
  16.     exit(1);
  17. }
  18.  
  19. int main(int argc,char *argv[])
  20. {
  21.     char NewLabel[12];
  22.     VolLabel vl;
  23.     unsigned char nDrive=0;
  24.     char cDrive;
  25.     char *szLabel, ch;
  26.  
  27.     cout << "Volume label changer." << endl << endl;
  28.  
  29.     if (argc>2)
  30.         ErrorMsg("Invalid number of parameters.");
  31.  
  32.     if (argc==2) {
  33.         cDrive=toupper(argv[1][0]);
  34.         if (strlen(argv[1])>2 || argv[1][1]!=':' || cDrive<'A' || cDrive>'Z')
  35.             ErrorMsg("Invalid parameter.");
  36.         nDrive='A'-cDrive+1;
  37.     }
  38.     else {
  39.         nDrive=vl.GetDisk();
  40.         cDrive='A'+nDrive;
  41.         ++nDrive;
  42.     }
  43.  
  44.  
  45.     if (!(szLabel=vl.GetLabel(nDrive)) && vl.IsError())
  46.         ErrorMsg("Error getting label.");
  47.  
  48.     cout << "The current label for drive " << cDrive << ": is "
  49.          << (char *) (szLabel!=0 ? szLabel : "none") << endl << endl;
  50.  
  51.     cout << "Enter new label (11 chars max): ";
  52.     cin.get(NewLabel,12);
  53.     cin.ignore();
  54.  
  55.     if (strlen(NewLabel)) {
  56.         if (!vl.SetLabel(nDrive,NewLabel))
  57.             ErrorMsg("Error while changing label.");
  58.     }
  59.     else {
  60.         cout << "Remove volume label (Y/N)?";
  61.         cin.get(ch);
  62.         if (toupper(ch)=='Y') {
  63.             if (!vl.Remove(nDrive))
  64.                 ErrorMsg("Error removing volume label.");
  65.             else
  66.                 cout << "Volume label removed." << endl;
  67.         }
  68.         else
  69.             cout << "Volume label not changed." << endl;
  70.     }
  71.     return 0;
  72. }